package com.will.txj.common.security;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Date;
import java.util.List;

/**
 * @author: wen-yi;
 * @date: 2021/11/25 23:42;
 * @Description:
 */
@Data
@TableName("aj_sys_user")
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="AJUser", description="AJ-WY统一认证用户")
public class AJUser extends Model<AJUser> implements UserDetails {
    private static final long serialVersionUID = 1L;

    @TableId(value = "id",type = IdType.AUTO)
    private Integer id;
    @ApiModelProperty("名字")
    private String name;
    @ApiModelProperty("用户名")
    private String username;
    @ApiModelProperty("密码")
    private String password;
    @ApiModelProperty("昵称")
    private String nickname;
    @ApiModelProperty("性别")
    private Integer sex;
    @ApiModelProperty("邮箱")
    private String email;
    @ApiModelProperty("头像")
    private String avatar;
    @ApiModelProperty("手机号码")
    private String phoneNumber;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty("生日")
    private Date birthday;
    @ApiModelProperty("用户是否未过期")
    private boolean accountNonExpired;
    @ApiModelProperty("用户是否未被锁定")
    private boolean accountNonLocked;
    @ApiModelProperty("凭证是否未过期")
    private boolean credentialsNonExpired;
    @ApiModelProperty("用户是否启用")
    public boolean enabled;
    /**
     * DateTimeFormat: 入参格式
     * JsonFormat： 出参格式
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty("创建时间")
    public Date cT;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty("最新更新时间")
    public Date uT;

    //返回用户生成的权限 权限不能返回null
    @TableField(exist = false)
    private List<GrantedAuthority> authorities;
}
